<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.9.2" />
<title>ascend.common.progressbar API documentation</title>
<meta name="description" content="" />
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
<link rel="preconnect" href="https://www.google.com">
<script async src="https://cse.google.com/cse.js?cx=017837193012385208679:pey8ky8gdqw"></script>
<style>
.gsc-control-cse {padding:0 !important;margin-top:1em}
body.gsc-overflow-hidden #sidebar {overflow: visible;}
</style>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
<style>.homelink{display:block;font-size:2em;font-weight:bold;color:#555;padding-bottom:.5em;border-bottom:1px solid silver}.homelink:hover{color:inherit}.homelink img{max-width:20%;max-height:5em;margin:auto;margin-bottom:.3em}</style>
<link rel="canonical" href="https://bazige.github.io/ascend/common/progressbar.html">
<link rel="icon" href="https://bazige.github.io/ascend/logo/logo.png"">
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>ascend.common.progressbar</code></h1>
</header>
<section id="section-intro">
<details class="source">
<summary>
<span>Expand source code</span>
<a href="https://github.com/pdoc3/pdoc/blob/37c907488ff52b174ab602690d1166f28bded9a2/ascend/common/progressbar.py#L0-L206" class="git-link">Browse git</a>
</summary>
<pre><code class="python"># Copyright (c) Open-MMLab. All rights reserved.
import sys
import time
from collections.abc import Iterable
from multiprocessing import Pool
from shutil import get_terminal_size


class ProgressBar:
    &#34;&#34;&#34;A progress bar which can print the progress.&#34;&#34;&#34;

    def __init__(self, task_num=0, bar_width=50, start=True, file=sys.stdout):
        self.task_num = task_num
        self.bar_width = bar_width
        self.completed = 0
        self.file = file
        if start:
            self.start()

    @property
    def terminal_width(self):
        width, _ = get_terminal_size()
        return width

    def start(self):
        if self.task_num &gt; 0:
            self.file.write(f&#39;[{&#34; &#34; * self.bar_width}] 0/{self.task_num}, &#39;
                            &#39;elapsed: 0s, ETA:&#39;)
        else:
            self.file.write(&#39;completed: 0, elapsed: 0s&#39;)
        self.file.flush()
        self.timer = time.time()

    def update(self, num_tasks=1):
        assert num_tasks &gt; 0
        self.completed += num_tasks
        elapsed = self.timer.since_start()
        if elapsed &gt; 0:
            fps = self.completed / elapsed
        else:
            fps = float(&#39;inf&#39;)
        if self.task_num &gt; 0:
            percentage = self.completed / float(self.task_num)
            eta = int(elapsed * (1 - percentage) / percentage + 0.5)
            msg = f&#39;\r[{{}}] {self.completed}/{self.task_num}, &#39; \
                  f&#39;{fps:.1f} task/s, elapsed: {int(elapsed + 0.5)}s, &#39; \
                  f&#39;ETA: {eta:5}s&#39;

            bar_width = min(self.bar_width,
                            int(self.terminal_width - len(msg)) + 2,
                            int(self.terminal_width * 0.6))
            bar_width = max(2, bar_width)
            mark_width = int(bar_width * percentage)
            bar_chars = &#39;&gt;&#39; * mark_width + &#39; &#39; * (bar_width - mark_width)
            self.file.write(msg.format(bar_chars))
        else:
            self.file.write(
                f&#39;completed: {self.completed}, elapsed: {int(elapsed + 0.5)}s,&#39;
                f&#39; {fps:.1f} tasks/s&#39;)
        self.file.flush()


def track_progress(func, tasks, bar_width=50, file=sys.stdout, **kwargs):
    &#34;&#34;&#34;Track the progress of tasks execution with a progress bar.

    Tasks are done with a simple for-loop.

    Args:
        func (callable): The function to be applied to each task.
        tasks (list or tuple[Iterable, int]): A list of tasks or
            (tasks, total num).
        bar_width (int): Width of progress bar.

    Returns:
        list: The task results.
    &#34;&#34;&#34;
    if isinstance(tasks, tuple):
        assert len(tasks) == 2
        assert isinstance(tasks[0], Iterable)
        assert isinstance(tasks[1], int)
        task_num = tasks[1]
        tasks = tasks[0]
    elif isinstance(tasks, Iterable):
        task_num = len(tasks)
    else:
        raise TypeError(
            &#39;&#34;tasks&#34; must be an iterable object or a (iterator, int) tuple&#39;)
    prog_bar = ProgressBar(task_num, bar_width, file=file)
    results = []
    for task in tasks:
        results.append(func(task, **kwargs))
        prog_bar.update()
    prog_bar.file.write(&#39;\n&#39;)
    return results


def init_pool(process_num, initializer=None, initargs=None):
    if initializer is None:
        return Pool(process_num)
    elif initargs is None:
        return Pool(process_num, initializer)
    else:
        if not isinstance(initargs, tuple):
            raise TypeError(&#39;&#34;initargs&#34; must be a tuple&#39;)
        return Pool(process_num, initializer, initargs)


def track_parallel_progress(func,
                            tasks,
                            nproc,
                            initializer=None,
                            initargs=None,
                            bar_width=50,
                            chunksize=1,
                            skip_first=False,
                            keep_order=True,
                            file=sys.stdout):
    &#34;&#34;&#34;Track the progress of parallel task execution with a progress bar.

    The built-in :mod:`multiprocessing` module is used for process pools and
    tasks are done with :func:`Pool.map` or :func:`Pool.imap_unordered`.

    Args:
        func (callable): The function to be applied to each task.
        tasks (list or tuple[Iterable, int]): A list of tasks or
            (tasks, total num).
        nproc (int): Process (worker) number.
        initializer (None or callable): Refer to :class:`multiprocessing.Pool`
            for details.
        initargs (None or tuple): Refer to :class:`multiprocessing.Pool` for
            details.
        chunksize (int): Refer to :class:`multiprocessing.Pool` for details.
        bar_width (int): Width of progress bar.
        skip_first (bool): Whether to skip the first sample for each worker
            when estimating fps, since the initialization step may takes
            longer.
        keep_order (bool): If True, :func:`Pool.imap` is used, otherwise
            :func:`Pool.imap_unordered` is used.

    Returns:
        list: The task results.
    &#34;&#34;&#34;
    if isinstance(tasks, tuple):
        assert len(tasks) == 2
        assert isinstance(tasks[0], Iterable)
        assert isinstance(tasks[1], int)
        task_num = tasks[1]
        tasks = tasks[0]
    elif isinstance(tasks, Iterable):
        task_num = len(tasks)
    else:
        raise TypeError(
            &#39;&#34;tasks&#34; must be an iterable object or a (iterator, int) tuple&#39;)
    pool = init_pool(nproc, initializer, initargs)
    start = not skip_first
    task_num -= nproc * chunksize * int(skip_first)
    prog_bar = ProgressBar(task_num, bar_width, start, file=file)
    results = []
    if keep_order:
        gen = pool.imap(func, tasks, chunksize)
    else:
        gen = pool.imap_unordered(func, tasks, chunksize)
    for result in gen:
        results.append(result)
        if skip_first:
            if len(results) &lt; nproc * chunksize:
                continue
            elif len(results) == nproc * chunksize:
                prog_bar.start()
                continue
        prog_bar.update()
    prog_bar.file.write(&#39;\n&#39;)
    pool.close()
    pool.join()
    return results


def track_iter_progress(tasks, bar_width=50, file=sys.stdout):
    &#34;&#34;&#34;Track the progress of tasks iteration or enumeration with a progress
    bar.

    Tasks are yielded with a simple for-loop.

    Args:
        tasks (list or tuple[Iterable, int]): A list of tasks or
            (tasks, total num).
        bar_width (int): Width of progress bar.

    Yields:
        list: The task results.
    &#34;&#34;&#34;
    if isinstance(tasks, tuple):
        assert len(tasks) == 2
        assert isinstance(tasks[0], Iterable)
        assert isinstance(tasks[1], int)
        task_num = tasks[1]
        tasks = tasks[0]
    elif isinstance(tasks, Iterable):
        task_num = len(tasks)
    else:
        raise TypeError(
            &#39;&#34;tasks&#34; must be an iterable object or a (iterator, int) tuple&#39;)
    prog_bar = ProgressBar(task_num, bar_width, file=file)
    for task in tasks:
        yield task
        prog_bar.update()
    prog_bar.file.write(&#39;\n&#39;)</code></pre>
</details>
</section>
<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="ascend.common.progressbar.init_pool"><code class="name flex">
<span>def <span class="ident">init_pool</span></span>(<span>process_num, initializer=None, initargs=None)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
<a href="https://github.com/pdoc3/pdoc/blob/37c907488ff52b174ab602690d1166f28bded9a2/ascend/common/progressbar.py#L97-L105" class="git-link">Browse git</a>
</summary>
<pre><code class="python">def init_pool(process_num, initializer=None, initargs=None):
    if initializer is None:
        return Pool(process_num)
    elif initargs is None:
        return Pool(process_num, initializer)
    else:
        if not isinstance(initargs, tuple):
            raise TypeError(&#39;&#34;initargs&#34; must be a tuple&#39;)
        return Pool(process_num, initializer, initargs)</code></pre>
</details>
</dd>
<dt id="ascend.common.progressbar.track_iter_progress"><code class="name flex">
<span>def <span class="ident">track_iter_progress</span></span>(<span>tasks, bar_width=50, file=sys.stdout)</span>
</code></dt>
<dd>
<div class="desc"><p>Track the progress of tasks iteration or enumeration with a progress
bar.</p>
<p>Tasks are yielded with a simple for-loop.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>tasks</code></strong> :&ensp;<code>list</code> or <code>tuple[Iterable, int]</code></dt>
<dd>A list of tasks or
(tasks, total num).</dd>
<dt><strong><code>bar_width</code></strong> :&ensp;<code>int</code></dt>
<dd>Width of progress bar.</dd>
</dl>
<h2 id="yields">Yields</h2>
<dl>
<dt><code>list</code></dt>
<dd>The task results.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
<a href="https://github.com/pdoc3/pdoc/blob/37c907488ff52b174ab602690d1166f28bded9a2/ascend/common/progressbar.py#L178-L207" class="git-link">Browse git</a>
</summary>
<pre><code class="python">def track_iter_progress(tasks, bar_width=50, file=sys.stdout):
    &#34;&#34;&#34;Track the progress of tasks iteration or enumeration with a progress
    bar.

    Tasks are yielded with a simple for-loop.

    Args:
        tasks (list or tuple[Iterable, int]): A list of tasks or
            (tasks, total num).
        bar_width (int): Width of progress bar.

    Yields:
        list: The task results.
    &#34;&#34;&#34;
    if isinstance(tasks, tuple):
        assert len(tasks) == 2
        assert isinstance(tasks[0], Iterable)
        assert isinstance(tasks[1], int)
        task_num = tasks[1]
        tasks = tasks[0]
    elif isinstance(tasks, Iterable):
        task_num = len(tasks)
    else:
        raise TypeError(
            &#39;&#34;tasks&#34; must be an iterable object or a (iterator, int) tuple&#39;)
    prog_bar = ProgressBar(task_num, bar_width, file=file)
    for task in tasks:
        yield task
        prog_bar.update()
    prog_bar.file.write(&#39;\n&#39;)</code></pre>
</details>
</dd>
<dt id="ascend.common.progressbar.track_parallel_progress"><code class="name flex">
<span>def <span class="ident">track_parallel_progress</span></span>(<span>func, tasks, nproc, initializer=None, initargs=None, bar_width=50, chunksize=1, skip_first=False, keep_order=True, file=sys.stdout)</span>
</code></dt>
<dd>
<div class="desc"><p>Track the progress of parallel task execution with a progress bar.</p>
<p>The built-in :mod:<code>multiprocessing</code> module is used for process pools and
tasks are done with :func:<code>Pool.map</code> or :func:<code>Pool.imap_unordered</code>.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>func</code></strong> :&ensp;<code>callable</code></dt>
<dd>The function to be applied to each task.</dd>
<dt><strong><code>tasks</code></strong> :&ensp;<code>list</code> or <code>tuple[Iterable, int]</code></dt>
<dd>A list of tasks or
(tasks, total num).</dd>
<dt><strong><code>nproc</code></strong> :&ensp;<code>int</code></dt>
<dd>Process (worker) number.</dd>
<dt><strong><code>initializer</code></strong> :&ensp;<code>None</code> or <code>callable</code></dt>
<dd>Refer to :class:<code>multiprocessing.Pool</code>
for details.</dd>
<dt><strong><code>initargs</code></strong> :&ensp;<code>None</code> or <code>tuple</code></dt>
<dd>Refer to :class:<code>multiprocessing.Pool</code> for
details.</dd>
<dt><strong><code>chunksize</code></strong> :&ensp;<code>int</code></dt>
<dd>Refer to :class:<code>multiprocessing.Pool</code> for details.</dd>
<dt><strong><code>bar_width</code></strong> :&ensp;<code>int</code></dt>
<dd>Width of progress bar.</dd>
<dt><strong><code>skip_first</code></strong> :&ensp;<code>bool</code></dt>
<dd>Whether to skip the first sample for each worker
when estimating fps, since the initialization step may takes
longer.</dd>
<dt><strong><code>keep_order</code></strong> :&ensp;<code>bool</code></dt>
<dd>If True, :func:<code>Pool.imap</code> is used, otherwise
:func:<code>Pool.imap_unordered</code> is used.</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>list</code></dt>
<dd>The task results.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
<a href="https://github.com/pdoc3/pdoc/blob/37c907488ff52b174ab602690d1166f28bded9a2/ascend/common/progressbar.py#L108-L175" class="git-link">Browse git</a>
</summary>
<pre><code class="python">def track_parallel_progress(func,
                            tasks,
                            nproc,
                            initializer=None,
                            initargs=None,
                            bar_width=50,
                            chunksize=1,
                            skip_first=False,
                            keep_order=True,
                            file=sys.stdout):
    &#34;&#34;&#34;Track the progress of parallel task execution with a progress bar.

    The built-in :mod:`multiprocessing` module is used for process pools and
    tasks are done with :func:`Pool.map` or :func:`Pool.imap_unordered`.

    Args:
        func (callable): The function to be applied to each task.
        tasks (list or tuple[Iterable, int]): A list of tasks or
            (tasks, total num).
        nproc (int): Process (worker) number.
        initializer (None or callable): Refer to :class:`multiprocessing.Pool`
            for details.
        initargs (None or tuple): Refer to :class:`multiprocessing.Pool` for
            details.
        chunksize (int): Refer to :class:`multiprocessing.Pool` for details.
        bar_width (int): Width of progress bar.
        skip_first (bool): Whether to skip the first sample for each worker
            when estimating fps, since the initialization step may takes
            longer.
        keep_order (bool): If True, :func:`Pool.imap` is used, otherwise
            :func:`Pool.imap_unordered` is used.

    Returns:
        list: The task results.
    &#34;&#34;&#34;
    if isinstance(tasks, tuple):
        assert len(tasks) == 2
        assert isinstance(tasks[0], Iterable)
        assert isinstance(tasks[1], int)
        task_num = tasks[1]
        tasks = tasks[0]
    elif isinstance(tasks, Iterable):
        task_num = len(tasks)
    else:
        raise TypeError(
            &#39;&#34;tasks&#34; must be an iterable object or a (iterator, int) tuple&#39;)
    pool = init_pool(nproc, initializer, initargs)
    start = not skip_first
    task_num -= nproc * chunksize * int(skip_first)
    prog_bar = ProgressBar(task_num, bar_width, start, file=file)
    results = []
    if keep_order:
        gen = pool.imap(func, tasks, chunksize)
    else:
        gen = pool.imap_unordered(func, tasks, chunksize)
    for result in gen:
        results.append(result)
        if skip_first:
            if len(results) &lt; nproc * chunksize:
                continue
            elif len(results) == nproc * chunksize:
                prog_bar.start()
                continue
        prog_bar.update()
    prog_bar.file.write(&#39;\n&#39;)
    pool.close()
    pool.join()
    return results</code></pre>
</details>
</dd>
<dt id="ascend.common.progressbar.track_progress"><code class="name flex">
<span>def <span class="ident">track_progress</span></span>(<span>func, tasks, bar_width=50, file=sys.stdout, **kwargs)</span>
</code></dt>
<dd>
<div class="desc"><p>Track the progress of tasks execution with a progress bar.</p>
<p>Tasks are done with a simple for-loop.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>func</code></strong> :&ensp;<code>callable</code></dt>
<dd>The function to be applied to each task.</dd>
<dt><strong><code>tasks</code></strong> :&ensp;<code>list</code> or <code>tuple[Iterable, int]</code></dt>
<dd>A list of tasks or
(tasks, total num).</dd>
<dt><strong><code>bar_width</code></strong> :&ensp;<code>int</code></dt>
<dd>Width of progress bar.</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>list</code></dt>
<dd>The task results.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
<a href="https://github.com/pdoc3/pdoc/blob/37c907488ff52b174ab602690d1166f28bded9a2/ascend/common/progressbar.py#L63-L94" class="git-link">Browse git</a>
</summary>
<pre><code class="python">def track_progress(func, tasks, bar_width=50, file=sys.stdout, **kwargs):
    &#34;&#34;&#34;Track the progress of tasks execution with a progress bar.

    Tasks are done with a simple for-loop.

    Args:
        func (callable): The function to be applied to each task.
        tasks (list or tuple[Iterable, int]): A list of tasks or
            (tasks, total num).
        bar_width (int): Width of progress bar.

    Returns:
        list: The task results.
    &#34;&#34;&#34;
    if isinstance(tasks, tuple):
        assert len(tasks) == 2
        assert isinstance(tasks[0], Iterable)
        assert isinstance(tasks[1], int)
        task_num = tasks[1]
        tasks = tasks[0]
    elif isinstance(tasks, Iterable):
        task_num = len(tasks)
    else:
        raise TypeError(
            &#39;&#34;tasks&#34; must be an iterable object or a (iterator, int) tuple&#39;)
    prog_bar = ProgressBar(task_num, bar_width, file=file)
    results = []
    for task in tasks:
        results.append(func(task, **kwargs))
        prog_bar.update()
    prog_bar.file.write(&#39;\n&#39;)
    return results</code></pre>
</details>
</dd>
</dl>
</section>
<section>
<h2 class="section-title" id="header-classes">Classes</h2>
<dl>
<dt id="ascend.common.progressbar.ProgressBar"><code class="flex name class">
<span>class <span class="ident">ProgressBar</span></span>
<span>(</span><span>task_num=0, bar_width=50, start=True, file=sys.stdout)</span>
</code></dt>
<dd>
<div class="desc"><p>A progress bar which can print the progress.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
<a href="https://github.com/pdoc3/pdoc/blob/37c907488ff52b174ab602690d1166f28bded9a2/ascend/common/progressbar.py#L9-L60" class="git-link">Browse git</a>
</summary>
<pre><code class="python">class ProgressBar:
    &#34;&#34;&#34;A progress bar which can print the progress.&#34;&#34;&#34;

    def __init__(self, task_num=0, bar_width=50, start=True, file=sys.stdout):
        self.task_num = task_num
        self.bar_width = bar_width
        self.completed = 0
        self.file = file
        if start:
            self.start()

    @property
    def terminal_width(self):
        width, _ = get_terminal_size()
        return width

    def start(self):
        if self.task_num &gt; 0:
            self.file.write(f&#39;[{&#34; &#34; * self.bar_width}] 0/{self.task_num}, &#39;
                            &#39;elapsed: 0s, ETA:&#39;)
        else:
            self.file.write(&#39;completed: 0, elapsed: 0s&#39;)
        self.file.flush()
        self.timer = time.time()

    def update(self, num_tasks=1):
        assert num_tasks &gt; 0
        self.completed += num_tasks
        elapsed = self.timer.since_start()
        if elapsed &gt; 0:
            fps = self.completed / elapsed
        else:
            fps = float(&#39;inf&#39;)
        if self.task_num &gt; 0:
            percentage = self.completed / float(self.task_num)
            eta = int(elapsed * (1 - percentage) / percentage + 0.5)
            msg = f&#39;\r[{{}}] {self.completed}/{self.task_num}, &#39; \
                  f&#39;{fps:.1f} task/s, elapsed: {int(elapsed + 0.5)}s, &#39; \
                  f&#39;ETA: {eta:5}s&#39;

            bar_width = min(self.bar_width,
                            int(self.terminal_width - len(msg)) + 2,
                            int(self.terminal_width * 0.6))
            bar_width = max(2, bar_width)
            mark_width = int(bar_width * percentage)
            bar_chars = &#39;&gt;&#39; * mark_width + &#39; &#39; * (bar_width - mark_width)
            self.file.write(msg.format(bar_chars))
        else:
            self.file.write(
                f&#39;completed: {self.completed}, elapsed: {int(elapsed + 0.5)}s,&#39;
                f&#39; {fps:.1f} tasks/s&#39;)
        self.file.flush()</code></pre>
</details>
<h3>Instance variables</h3>
<dl>
<dt id="ascend.common.progressbar.ProgressBar.terminal_width"><code class="name">var <span class="ident">terminal_width</span></code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
<a href="https://github.com/pdoc3/pdoc/blob/37c907488ff52b174ab602690d1166f28bded9a2/ascend/common/progressbar.py#L20-L23" class="git-link">Browse git</a>
</summary>
<pre><code class="python">@property
def terminal_width(self):
    width, _ = get_terminal_size()
    return width</code></pre>
</details>
</dd>
</dl>
<h3>Methods</h3>
<dl>
<dt id="ascend.common.progressbar.ProgressBar.start"><code class="name flex">
<span>def <span class="ident">start</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
<a href="https://github.com/pdoc3/pdoc/blob/37c907488ff52b174ab602690d1166f28bded9a2/ascend/common/progressbar.py#L25-L32" class="git-link">Browse git</a>
</summary>
<pre><code class="python">def start(self):
    if self.task_num &gt; 0:
        self.file.write(f&#39;[{&#34; &#34; * self.bar_width}] 0/{self.task_num}, &#39;
                        &#39;elapsed: 0s, ETA:&#39;)
    else:
        self.file.write(&#39;completed: 0, elapsed: 0s&#39;)
    self.file.flush()
    self.timer = time.time()</code></pre>
</details>
</dd>
<dt id="ascend.common.progressbar.ProgressBar.update"><code class="name flex">
<span>def <span class="ident">update</span></span>(<span>self, num_tasks=1)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
<a href="https://github.com/pdoc3/pdoc/blob/37c907488ff52b174ab602690d1166f28bded9a2/ascend/common/progressbar.py#L34-L60" class="git-link">Browse git</a>
</summary>
<pre><code class="python">def update(self, num_tasks=1):
    assert num_tasks &gt; 0
    self.completed += num_tasks
    elapsed = self.timer.since_start()
    if elapsed &gt; 0:
        fps = self.completed / elapsed
    else:
        fps = float(&#39;inf&#39;)
    if self.task_num &gt; 0:
        percentage = self.completed / float(self.task_num)
        eta = int(elapsed * (1 - percentage) / percentage + 0.5)
        msg = f&#39;\r[{{}}] {self.completed}/{self.task_num}, &#39; \
              f&#39;{fps:.1f} task/s, elapsed: {int(elapsed + 0.5)}s, &#39; \
              f&#39;ETA: {eta:5}s&#39;

        bar_width = min(self.bar_width,
                        int(self.terminal_width - len(msg)) + 2,
                        int(self.terminal_width * 0.6))
        bar_width = max(2, bar_width)
        mark_width = int(bar_width * percentage)
        bar_chars = &#39;&gt;&#39; * mark_width + &#39; &#39; * (bar_width - mark_width)
        self.file.write(msg.format(bar_chars))
    else:
        self.file.write(
            f&#39;completed: {self.completed}, elapsed: {int(elapsed + 0.5)}s,&#39;
            f&#39; {fps:.1f} tasks/s&#39;)
    self.file.flush()</code></pre>
</details>
</dd>
</dl>
</dd>
</dl>
</section>
</article>
<nav id="sidebar">
<header>
<a class="homelink" rel="home" title="ascendfly Home" href="https://gitee.com/ascend-fae/ascendfly">
<img src="https://bazige.github.io/ascend/logo/logo.png" alt=""> ascendfly
</a>
</header>
<div class="gcse-search" style="height: 70px"
data-as_oq="site:bazige.github.io inurl:github.com/ascendfly"
data-gaCategoryParameter="ascend.common.progressbar">
</div>
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3>Super-module</h3>
<ul>
<li><code><a title="ascend.common" href="index.html">ascend.common</a></code></li>
</ul>
</li>
<li><h3><a href="#header-functions">Functions</a></h3>
<ul class="">
<li><code><a title="ascend.common.progressbar.init_pool" href="#ascend.common.progressbar.init_pool">init_pool</a></code></li>
<li><code><a title="ascend.common.progressbar.track_iter_progress" href="#ascend.common.progressbar.track_iter_progress">track_iter_progress</a></code></li>
<li><code><a title="ascend.common.progressbar.track_parallel_progress" href="#ascend.common.progressbar.track_parallel_progress">track_parallel_progress</a></code></li>
<li><code><a title="ascend.common.progressbar.track_progress" href="#ascend.common.progressbar.track_progress">track_progress</a></code></li>
</ul>
</li>
<li><h3><a href="#header-classes">Classes</a></h3>
<ul>
<li>
<h4><code><a title="ascend.common.progressbar.ProgressBar" href="#ascend.common.progressbar.ProgressBar">ProgressBar</a></code></h4>
<ul class="">
<li><code><a title="ascend.common.progressbar.ProgressBar.start" href="#ascend.common.progressbar.ProgressBar.start">start</a></code></li>
<li><code><a title="ascend.common.progressbar.ProgressBar.terminal_width" href="#ascend.common.progressbar.ProgressBar.terminal_width">terminal_width</a></code></li>
<li><code><a title="ascend.common.progressbar.ProgressBar.update" href="#ascend.common.progressbar.ProgressBar.update">update</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p><span style="color:#ddd">&#21328;</span></p>
<p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.9.2</a>.</p>
</footer>
</body>
</html>